-- card: 12248 from stack: in.3 -- bmap block id: 0 -- flags: 4000 -- background id: 3241 -- name: ObjectExists ----- HyperTalk script ----- on Install get ChooseTargetStack() InstallResource XFCN,ObjectExists,it end Install -- part 1 (field) -- low flags: 81 -- high flags: 2007 -- rect: left=12 top=26 right=298 bottom=491 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 22 -- text size: 10 -- style flags: 0 -- line height: 13 -- part name: Source -- part 2 (button) -- low flags: 00 -- high flags: A003 -- rect: left=299 top=300 right=322 bottom=438 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Show Pascal Source ----- HyperTalk script ----- on mouseUp set the visible of card field 1 to not the visible of card field 1 if the visible of card field 1 is true then set the name of me to "Hide Pascal Source" else set the name of me to "Show Pascal Source" end mouseUp -- part contents for background part 16 ----- text ----- OBJECTEXISTS XFCN version 1.0 Kevin Calhoun ObjectExists determines whether or not a HyperCard object exists. The bad news is that it's not perfect, for three reasons: 1) If you want to ask by name (rather than by id or number) about an object with a short name longer than one word, you have to store the long name of the object in a container and then pass the container to ObjectExists. For instance, to find out about card button "Show Pascal Source", you can use the following HyperTalk code: put "card btn" && quote & "Show Pascal Source" & quote into theButton get ObjectExists(theButton) This is an instance of the general problem of quoting in HyperCard. 2) If you want to find out whether a stack exists and the stack does not exist in any directory contained in the current Home stack's "Look for stacks in…" field, HyperCard will invoke the standard file package and ask the user to find the stack. If the user selects a stack from the standard file dialog, ObjectExists returns TRUE whether or not the user selected the stack you designated. If the user presses Cancel, ObjectExists returns FALSE, regardless of whether the stack is actually on the disk. 3) In versions of HyperCard earlier than 1.2, it causes the dreaded "Never heard of…" dialog box to appear when the object you designate does not exist. INVOKING OBJECTEXISTS get ObjectExists(objectDesignation) result: true or false EXAMPLES get ObjectExists("card field Watusi") get ObjectExists("bg btn 15") get ObjectExists("card id 2731") get ObjectExists("stack Home") get ObjectExists("background WildCard") -- part contents for card part 1 ----- text ----- UNIT BecauseRogerAskedForIt; { This XFCN requires HyperCard 1.2 or later } { ObjectExists XFCN ©1989 by the Trustees of Dartmouth College } { Written by Kevin Calhoun } { This source compatible with MPW Pascal 3.0 } (* Pascal ObjectExists.p Link -m ENTRYPOINT ∂ -o "YourFile" ∂ -rt XFCN=19051 ∂ -sn Main=ObjectExists ∂ ObjectExists.p.o ∂ "{Libraries}"interface.o ∂ "{PLibraries}"Paslib.o ∂ "{Libraries}"HyperXLib.o *) {$R-} interface USES Types, Memory, HyperXCmd; PROCEDURE EntryPoint (paramPtr : XCMDPtr); IMPLEMENTATION {-----------------------------------------------------------------} PROCEDURE ObjectExists (paramPtr: XCMDPtr); FORWARD; PROCEDURE EntryPoint (paramPtr : XCMDPtr); BEGIN ObjectExists(paramPtr); END; PROCEDURE ObjectExists (paramPtr: XCMDPtr); VAR s: Str255; h: Handle; BEGIN IF paramPtr^.paramCount > 0 THEN BEGIN ZeroToPas(paramPtr, paramPtr^.params[1]^, s); h := EvalExpr(paramPtr, CONCAT('the name of ',s)); BoolToStr(paramPtr,(paramPtr^.result = noErr), s); paramPtr^.returnValue := PasToZero(paramPtr, s); IF h <> NIL THEN DisposHandle(h); END ELSE paramPtr^.returnValue := PasToZero(paramPtr, 'ObjectExists XFCN 1.0, 15 March 1989, ©1989 Dartmouth College'); END; END.